<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery-1.8.3.js"></script>
</head>
<body>
<table border="1px" cellspacing="0" cellpadding="0" id="ordTb">
    <tr id="ordHead">
        <td>订单号</td>
        <td>商品号</td>
        <td>用户名</td>
        <td>下单时间</td>
    </tr>
</table>
<a href="#" id="first" class="pages">首页</a>
<a href="#" id="prev" class="pages">上一页</a>
<a href="#" id="next" class="pages">下一页</a>
<a href="#" id="last" class="pages">尾页</a>
<script>
    var currPage;
    var toPage;
    $(function () {
        var getOrderList = function (curr) {
            $.ajax({
                type: "POST",
                url: "getallOrderServlet",
                dataType: "JSON",
                data: {
                    pageSize: 2,
                    pageNum: curr || 1
                },
                success: function (data) {
                    console.log(data);
                    $("#ordTb").find("tr[class='orderdata']").remove();
                    $.each(data.orderList, function (index, obj) {
                        var $ordertr = "<tr class='orderdata'>" +
                            "<td>" + obj.orderId + "</td>" +
                            "<td>" + obj.goods.goodsname + "</td>" +
                            "<td>" + obj.user.username + "</td>" +
                            "<td>" + obj.orderTime + "</td>" +
                            "</tr>";
                        $("#ordTb").append($ordertr);
                    });
                    currPage = data.pageindex;
                    toPage = data.totalpages;
                }
            })
        };
        $(".pages").click(function () {
            var flag = $(this).attr("id");
            if (flag == "first") {
                getOrderList(1)
            } else if (flag == "prev") {
                currPage--;
                getOrderList(currPage)
            } else if (flag == "next") {
                currPage++;
                getOrderList(currPage);
            } else {
                getOrderList(toPage);
            }
        });
        getOrderList();

    })

</script>
</body>
</html>